package com.zlf.sb.demo.juc;

/***
 *@title BankAccount
 *@description <TODO description class purpose>
 *@author wgc_j
 *@version 1.0.0
 *@create 2025-02-26 10:00
 **/
public class BankAccount {
    private double balance;  // 账户余额
    // 构造函数


    public BankAccount(double initialBalance) {
        this.balance = initialBalance;
    }    // 存款方法

    public synchronized void deposit(double amount) {
        // 增加余额
        balance += amount;
        System.out.println("Deposited " + amount + ". New balance is " + balance);
    }    // 取款方法

    public synchronized void withdraw(double amount) {
        if (amount <= balance) {
            balance -= amount;
            System.out.println("Withdrew " + amount + ". Remaining balance is " + balance);
        } else {
            System.out.println("Insufficient funds for withdrawal!");
        }
    }
    // 获取余额


    public synchronized double getBalance() {
        return balance;
    }

}